class code1 {
    public boolean isValid(String s) {
        Stack<Character> st = new Stack<>();
        HashMap<Character,Character> map = new HashMap<>();
        map.put('(',')');
        map.put('[',']');
        map.put('{','}');
        for(char ch:s.toCharArray()) {
            if(map.containsKey(ch)) {
                st.push(ch);
            } else if(!st.isEmpty() &&  ch == map.get(st.peek())) {
                st.pop();
            } else {
                return false;
            }
        }
        return st.isEmpty();
    }
}